// 防抖
// export function _debounce(fn, delay) {

//     var delay = delay || 200;
//     var timer;
//     return function () {
//         var th = this;
//         var args = arguments;
//         if (timer) {
//             clearTimeout(timer);
//         }
//         timer = setTimeout(function () {
//             timer = null;
//             fn.apply(th, args);
//         }, delay);
//     };
// }
export function toFixedDigit(num,n){//保留n位
	if(typeof num != 'number'){
		return false;
	};
	num = num.toString();
	var result = "";
	var zeroResult = function(n){
		var zero = "";
		for(var i = 0;i<n;i++){
			zero+="0";
		}
		return zero;
	}
	if(num%1 == 0){//整数
		result = num + "."+zeroResult(n);
	}else{//小数
		var num1 = num.split(".");
		if(num1[1].length<n){
		   result = num1[0]+"."+num1[1]+zeroResult(n-num1[1].length)
		}else{
		   result = num1[0]+"."+num1[1].substring(0,n)
		}
	}
	return result;
}
export function _debounce(func,delay) {
    let timeout;
	var delay = delay || 200;
    return function () {
        let context = this;
        let args = arguments;

        if (timeout) clearTimeout(timeout);

        let callNow = !timeout;
        timeout = setTimeout(() => {
            timeout = null;
        }, delay)

        if (callNow) func.apply(context, args)
    }
}
// 节流
export function _throttle(fn, interval) {
    var last;
    var timer;
    var interval = interval || 200;
    return function () {
        var th = this;
        var args = arguments;
        var now = +new Date();
        if (last && now - last < interval) {
            clearTimeout(timer);
            timer = setTimeout(function () {
                last = now;
                fn.apply(th, args);
            }, interval);
        } else {
            last = now;
            fn.apply(th, args);
        }
    }
}